package com.financing.wap.util;

import java.util.Collections;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;

/**
 * 
* @ClassName: 解析json 
* @author lisu 
*
 */
public class JSONUtil {
	
	public static Logger log = Logger.getLogger(JSONUtil.class);
	
	
	/**
	 * @param jsonStr
	 * @return
	 */
	public static  List<?> getListForJson(String jsonStr,Class<?> objectClass) throws Exception {
		if(StringUtil.isNullOrEmptyStr(jsonStr)){
			return  Collections.EMPTY_LIST;
		}
		JSONArray jsonData = JSONArray.fromObject(jsonStr);
		List<?> list = (List<?>)JSONArray.toCollection(jsonData, objectClass);
		return list;
	}
	public static  Object getObjectForJson(String jsonStr,Class<?> objectClass) throws Exception{
		if(StringUtil.isNullOrEmptyStr(jsonStr)){
			return objectClass.newInstance();
		}
		JSONObject json = JSONObject.fromObject(jsonStr);  
		Object bean = JSONObject.toBean(json, objectClass);
		return bean;
	}
}
